package com.itheima.mapper;

import com.itheima.domain.Trip;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

//映射接口
public interface TripMapper {

    /**
     * 功能: 查询行程表中的所有数据
     * @return  查询的行程对象
     */
    @Select("select *from tb_trip")
    public List<Trip> findAllTrip();


    /**
     * 功能：添加行程
     * @param trip
     * @return 受影响行
     */
    @Insert("insert into tb_trip values " +
            "(null,#{username},#{gender},#{idCard},#{fromAddress},#{toAddress},#{startTime})")
    public int addTrip(Trip trip);


    /**
     * 功能：根据id查找行程
     * @param id 行程 id
     * @return 行程对象
     */
    @Select("select *from tb_trip where id=#{id}")
    public Trip queryTripById(Integer id);


    /**
     * 功能：根据行程id 修改行程数据
     * @param id 行程id
     * @return  受影响行
     */
    @Update("update tb_trip set username =#{username},gender=#{gender},idcard=#{idCard}," +
            "from_address=#{fromAddress},to_address=#{toAddress},start_time = #{startTime} where id =#{id}")
    public int updateTripById(Integer id);


    /**
     * 功能：根据id删除行程数据
     * @param id 行程id
     * @return  受影响行
     */
    @Delete("delete from tb_trip where id=#{id}")
    public int deleteTripById(Long id);


}
